<template>
	<view>
		<view class="mp_info">
			<view class="mp_sum">
				<text class="sum_text">总发布</text>
				<text class="sum">
					{{sum}}
				</text>
				<button class="mp_button" @click="goto('../../subpages/sends/sends_goods')">我要发布</button>
			</view>
			<view class="tabs_info">
				<view class="mp_tabs">
					<u-tabs-swiper ref="tabs" :list="list" @change="change" :is-scroll="false" height="90"
						:show-bar="false" activeColor="rgba(255, 87, 51, 1)"></u-tabs-swiper>
				</view>
				<swiper class="swiper-box" :current="swiperCurrent" @transition="transition"
					@animationfinish="animationfinish">
					<swiper-item class="swiper-item">
						<scroll-view scroll-y style="height:100%;width: 100%;" @scrolltolower="onreachBottom">
							<view class="publish_allinfo">
								<view v-for="(on_saleitem,on_saleindex) in on_sale" :key="on_saleindex"
									class="publish_info">
									<publishcard :on_saleitem="on_saleitem"></publishcard>
								</view>
							</view>
						</scroll-view>
					</swiper-item>
					<swiper-item class="swiper-item">
						<scroll-view scroll-y style="height:100%;width: 100%;" @scrolltolower="onreachBottom">
							<view class="publish_allinfo">
								<view v-for="(presellitem,presellindex) in presell" :key="presellindex"
									class="publish_info">
									<publishcard :on_saleitem="presellitem"></publishcard>
								</view>
							</view>
						</scroll-view>
					</swiper-item>
					<swiper-item class="swiper-item">
						<scroll-view scroll-y style="height:100%;width: 100%;" @scrolltolower="onreachBottom">
							<view class="publish_allinfo">
								<view v-for="(sell_outitem,sell_outindex) in sell_out" :key="sell_outindex"
									class="publish_info">
									<publishcard :on_saleitem="sell_outitem"></publishcard>
								</view>
							</view>
						</scroll-view>
					</swiper-item>
				</swiper>
			</view>
		</view>
		<u-back-top :scroll-top="scrollTop" mode="square" tips="顶部"></u-back-top>
		<!-- <u-divider color="#878787" bg-color="rgba(255, 255, 255, 1)" margin-top="20" margin-bottom="20">到底了</u-divider> -->
	</view>
</template>

<script>
	import publishcard from '../../components/publishcard/publishcard.vue'
	export default {
		components:{
			publishcard
		},
		data() {
			return {
				//回到顶部
				scrollTop: 0,
				need_card_list: [],
				cardshow: 0,
				//tabs标识
				dx: 0,
				sum: 0,
				current: 0,
				swiperCurrent: 0,
				list: [{
					name: '在售'
				}, {
					name: '预售'
				}, {
					name: '已售'
				}],
				on_sale: [],
				presell: [],
				sell_out: []
			}
		},
		methods: {
			//页面跳转
			goto(url) {
				uni.navigateTo({
					url: url,
					animationType: 'slide-in-right',
					animationDuration: 1000
				})
			},
			getMyPublishInfo() {
				this.$myRequest({
					url: '/goods/getMyPublishGoods',
					method: 'POST',
					data:{
						'status':this.swiperCurrent
					}
				}).then((res) => {
					console.log(res)
					if (res.data.code == 200) {
						if(this.swiperCurrent===0){
							this.on_sale = res.data.data
						}
						if(this.swiperCurrent===1){
							this.presell = res.data.data
						}
					}
				})
			},
			getSum(){
				this.$myRequest({
					url:'/goods/getMyPublishGoodsNum',
					method:'POST',
					data:{
					}
				}).then((res) => {
					if (res.data.code == 200){
						this.sum = res.data.data
					}
				})
			},
			// tab栏切换
			change(index) {
				this.swiperCurrent = index;
				this.getMyPublishInfo();
				// console.log(this.swiperCurrent)
				// this.getOrderList(index);
			},
			transition({
				detail: {
					dx
				}
			}) {
				this.$refs.tabs.setDx(dx);
			},
			animationfinish({
				detail: {
					current
				}
			}) {
				this.$refs.tabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.current = current;
			}
		},
		mounted() {
			this.getSum();//请求发布数量
			this.getMyPublishInfo(); //请求商品数据

		},
		onPageScroll(e) { //生命周期函数

		}
	}
</script>

<style>
	@import url("my_publish.css");
</style>
